package com.example.web.controller;


import cn.dev33.satoken.annotation.SaCheckRole;
import com.example.common.response.R;
import com.example.system.domain.Bo.ProcessBo;
import com.example.system.service.ProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(value = "项目审核管理", tags = {"项目审核管理"})
@RequestMapping(value = "/process", method = {RequestMethod.POST, RequestMethod.GET})
public class ProcessController {
    @Autowired
    private ProcessService processService;

    @ResponseBody
    @ApiOperation("获取某一项目的审核人员名单")
    @RequestMapping(value = "/getShareUser/shareUser/{projectId}")
    public R<List<Integer>> getShareUser(@PathVariable("projectId") Integer projectId) {
        List<Integer> list = processService.getOneProjectShareUser(projectId);
        return R.ok(list);
    }

    @ResponseBody
    @ApiOperation("获取搜索审核人员名单")
    @RequestMapping(value = "/getShareUser/allShareUser")
    public R<List<Map<String, Object>>> getAllShareUser() {
        List<Map<String, Object>> list = processService.getAllShareUser();
        return R.ok(list);
    }

    @ResponseBody
    @SaCheckRole("初级审核人员")
    @ApiOperation("审核人员提交项目审核结果")
    @RequestMapping("/updateProcess")
    public R<String> updateProcess(@RequestBody ProcessBo processBo) {
        processService.updateProcess(processBo);
        return R.ok("提交成功");
    }

    @ResponseBody
    @SaCheckRole("管理员")
    @ApiOperation("更改某一项目的审核人员名单")
    @RequestMapping("/changeUserProcess/{projectId}")
    public R<String> changeUP(@RequestBody List<Integer> userIdS,
                              @PathVariable("projectId") Integer projectId) {
        processService.changeUP(userIdS, projectId);
        return R.ok("分配成功");
    }
}
